/*
 * @Author: szx
 * @Date: 2022-03-15 12:48:23
 * @LastEditTime: 2022-03-15 13:14:04
 * @Description:
 * @FilePath: \leetcode\2000-2099\2044\2044.js
 */
/**
 * @param {number[]} nums
 * @return {number}
 */
var countMaxOrSubsets = function (nums) {
    const n = nums.length;
    let ans = 0;
    let max = -Infinity;
    const backtrace = (path, index, res) => {
        if (res > max) {
            max = res;
            ans = 1;
        } else if (res == max) {
            ans++;
        } else return;
        for (let i = index; i < n; i++) {
            path.push(nums[i]);
            backtrace(path, i + 1, res | nums[i]);
            path.pop();
        }
    };
    backtrace([], 0, 0);
    return ans;
};

console.log(countMaxOrSubsets([1, 3]));
console.log(countMaxOrSubsets([2, 2, 2]));
console.log(countMaxOrSubsets([3, 2, 1, 5]));
